package com.zbkj.admin.controller.merchant;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.water.RzStore;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.water.RzStoreSaveRequest;
import com.zbkj.common.request.water.RzStoreSaveReturn;
import com.zbkj.common.request.water.RzStoreSearchRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.water.RzStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺管理 前端控制器
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/merchant/store")
@Api(tags = "商户店铺管理控制器")
public class RzStoreController {

    @Autowired
    private RzStoreService rzStoreService;

    @PreAuthorize("hasAuthority('merchant:store:list')")
    @ApiOperation(value = "店铺分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<RzStoreSaveReturn>> getList(@Validated RzStoreSearchRequest request) {
        return CommonResult.success(CommonPage.restPage(rzStoreService.getPage(request)));
    }

    @PreAuthorize("hasAuthority('merchant:store:add')")
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.ADD, description = "新增店铺")
    @ApiOperation(value = "新增店铺")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<Object> save(@RequestBody RzStoreSaveRequest request) {
        if (rzStoreService.add(request)) {
            return CommonResult.success().setMessage("新增店铺成功");
        }
        return CommonResult.failed().setMessage("新增店铺失败");
    }

    @PreAuthorize("hasAuthority('merchant:store:update')")
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "修改店铺")
    @ApiOperation(value = "修改店铺")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<Object> update(@RequestBody RzStoreSaveRequest request) {
        if (rzStoreService.updateStore(request)) {
            return CommonResult.success().setMessage("修改店铺成功");
        }
        return CommonResult.failed().setMessage("修改店铺失败");
    }

    @PreAuthorize("hasAuthority('merchant:store:delete')")
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "删除店铺")
    @ApiOperation(value = "删除店铺")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public CommonResult<Object> delete(@PathVariable(value = "id") Integer id) {
        if (rzStoreService.deleteById(id)) {
            return CommonResult.success().setMessage("删除店铺成功");
        }
        return CommonResult.failed().setMessage("删除店铺失败");
    }
}
